/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.economy.model;

import java.util.Date;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import ar.uba.fi.posgrado.common.model.AbstractDomainObject;
import ar.uba.fi.posgrado.common.model.Address;

/**
 * Cliente
 * 
 * @author pablo.tortorella
 */

@Entity
@Table(name = "CLIENTE")
@SuppressWarnings("serial")
public class Customer extends AbstractDomainObject {

	// TODO faltan situacion ante la AFIP (resp inscripto, etc), direccion
	// desglosada, cuenta corriente, etc

	@Column(name = "NOMBRE", length = 45)
	private String name;

	@Column(name = "RAZON_SOCIAL", length = 255, unique = true)
	private String corporateName;

	@Embedded
	@AttributeOverrides( {
			@AttributeOverride(name = "street", column = @Column(name = "DIRECCION_CALLE")),
			@AttributeOverride(name = "number", column = @Column(name = "DIRECCION_NUMERO")),
			@AttributeOverride(name = "floor", column = @Column(name = "DIRECCION_PISO")),
			@AttributeOverride(name = "room", column = @Column(name = "DIRECCION_DEPARTAMENTO")),
			@AttributeOverride(name = "city", column = @Column(name = "DIRECCION_CIUDAD")),
			@AttributeOverride(name = "town", column = @Column(name = "DIRECCION_LOCALIDAD")),
			@AttributeOverride(name = "zipcode", column = @Column(name = "DIRECCION_CODIGO_POSTAL")) })
	private Address address;

	@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "ID_CUENTA_CORRIENTE")
	private CustomerAccount account;

	@Column(name = "FECHA_ALTA")
	private Date registerDate;

	@Column(name = "DOCUMENTO", length = 14)
	private String document;

	@Column(name = "CONDICION_TRIBUTARIA", length = 40)
	private String terms;

	@Column(name = "TELEFONO", length = 25)
	private String phone;

	@Column(name = "TELEFONO_CELULAR", length = 25)
	private String mobile;

	@Column(name = "EMAIL", length = 75)
	private String email;

	@Column(name = "CONTACTO", length = 75)
	private String contact;

	/**
	 * @return the contact
	 */
	public String getContact() {
		return contact;
	}

	/**
	 * @param contact
	 *            the contact to set
	 */
	public void setContact(String contact) {
		this.contact = contact;
	}

	/**
	 * @return the document
	 */
	public String getDocument() {
		return document;
	}

	/**
	 * @param document
	 *            the document to set
	 */
	public void setDocument(String document) {
		this.document = document;
	}

	/**
	 * @return the registerDate
	 */
	public Date getRegisterDate() {
		return registerDate;
	}

	/**
	 * @param registerDate
	 *            the registerDate to set
	 */
	public void setRegisterDate(Date registerDate) {
		this.registerDate = registerDate;
	}

	/**
	 * Condicion impositiva
	 * 
	 * @return the terms
	 */
	public String getTerms() {
		return terms;
	}

	/**
	 * Condicion impositiva
	 * 
	 * @param terms
	 *            the terms to set
	 */
	public void setTerms(String terms) {
		this.terms = terms;
	}

	/**
	 * Constructor
	 */
	public Customer() {
	}

	/**
	 * @return the address
	 */
	public Address getAddress() {
		return address;
	}

	/**
	 * @param address
	 *            the address to set
	 */
	public void setAddress(Address address) {
		this.address = address;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the corporateName
	 */
	public String getCorporateName() {
		return corporateName;
	}

	/**
	 * @param corporateName
	 *            the corporateName to set
	 */
	public void setCorporateName(String razonSocial) {
		this.corporateName = razonSocial;
	}

	/**
	 * @return the account
	 */
	public CustomerAccount getAccount() {
		return this.account;
	}

	/**
	 * @param account
	 *            the account to set
	 */
	public void setAccount(CustomerAccount account) {
		this.account = account;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ar.uba.fi.posgrado.common.model.AbstractDomainObject#getExcludedFields()
	 */
	@Override
	public String[] getExcludedFields() {
		return new String[] { "name", "address", "account", "registerDate",
				"terms", "phone", "mobile" };
	}

	@Override
	public String toString() {
		return this.getCorporateName();
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the mobile
	 */
	public String getMobile() {
		return mobile;
	}

	/**
	 * @param mobile
	 *            the mobile to set
	 */
	public void setMobile(String mobileNumber) {
		this.mobile = mobileNumber;
	}

	/**
	 * @return the phone
	 */
	public String getPhone() {
		return phone;
	}

	/**
	 * @param phone
	 *            the phone to set
	 */
	public void setPhone(String phoneNumber) {
		this.phone = phoneNumber;
	}

}
